import axios from "axios";
//基础写 路由
const axiosw = axios.create({
    baseURL:'http://101.201.170.32:8888/T6',
    timeout:10000
})

const axioswmedical = axios.create({
    baseURL:'http://101.201.170.32:8888/T8',
  timeout:10000
})

const axiosimg = axios.create({
  baseURL:'http://101.201.170.32:8888/T9',
  timeout:10000
})

const axioswnewmedical = axios.create({
  baseURL:'http://101.201.170.32:8888/T11',
  timeout:10000
})

const axioswzsh = axios.create({
    baseURL:'http://101.201.170.32:5283/api',
    timeout:10000
})
// 添加请求拦截器
axiosw.interceptors.request.use(function (config) {
    // 数据提交后端要加入新的Token值
        config.headers["Authorization"] =
            "Bearer " + localStorage.getItem("token");
    // 在发送请求之前做些什么
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });

// 添加响应拦截器
axiosw.interceptors.response.use(function (response) {
    // 2xx 范围内的状态码都会触发该函数。
    // 对响应数据做点什么
    return response;
  }, function (error) {
    // 超出 2xx 范围的状态码都会触发该函数。
    // 对响应错误做点什么
    return Promise.reject(error);
  });

  // 添加请求拦截器
axioswmedical.interceptors.request.use(function (config) {
    // 数据提交后端要加入新的Token值
        config.headers["Authorization"] =
            "Bearer " + localStorage.getItem("token");
    // 在发送请求之前做些什么
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });

// 添加响应拦截器
axioswmedical.interceptors.response.use(function (response) {
    // 2xx 范围内的状态码都会触发该函数。
    // 对响应数据做点什么
    return response;
  }, function (error) {
    // 超出 2xx 范围的状态码都会触发该函数。
    // 对响应错误做点什么
    return Promise.reject(error);
  });

// 添加请求拦截器 - axiosimg
axiosimg.interceptors.request.use(function (config) {
    // 数据提交后端要加入新的Token值
        config.headers["Authorization"] =
            "Bearer " + localStorage.getItem("token");
    // 在发送请求之前做些什么
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });

// 添加响应拦截器 - axiosimg
axiosimg.interceptors.response.use(function (response) {
    // 2xx 范围内的状态码都会触发该函数。
    // 对响应数据做点什么
    return response;
  }, function (error) {
    // 超出 2xx 范围的状态码都会触发该函数。
    // 对响应错误做点什么
    return Promise.reject(error);
  });

// 添加请求拦截器 - axioswnewmedical
axioswnewmedical.interceptors.request.use(function (config) {
    // 数据提交后端要加入新的Token值
        config.headers["Authorization"] =
            "Bearer " + localStorage.getItem("token");
    // 在发送请求之前做些什么
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });

// 添加响应拦截器 - axioswnewmedical
axioswnewmedical.interceptors.response.use(function (response) {
    // 2xx 范围内的状态码都会触发该函数。
    // 对响应数据做点什么
    return response;
  }, function (error) {
    // 超出 2xx 范围的状态码都会触发该函数。
    // 对响应错误做点什么
    return Promise.reject(error);
  });

// 上传文件接口
export function uploadFile(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  return axiosimg.post('/FileUpload/UploadFile', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 新增轮播图接口
export function addCarousel(data: {
  title: string;
  image: string;
  link: string;
  number: number;
  status: boolean;
  createPeople: string;
}) {
  return axioswnewmedical.post('/Carousel/AddCarousel', data);
}

// 修改轮播图接口
export function updateCarousel(data: {
  id: number;
  title: string;
  image: string;
  link: string;
  number: number;
  status: boolean;
  updatePeople: string;
}) {
  return axioswnewmedical.put('/Carousel/UpdateCarousel', data);
}

// 删除轮播图接口
export function deleteCarousels(data: {
  ids: number[];
  updatePeople: string;
}) {
  return axioswnewmedical.delete('/Carousel/DeleteCarousels', { data });
}

// 新增患者接口
export function addPatient(data: {
  accountId: number;
  name: string;
  sex: boolean;
  dateOfBirth: string;
  contactInfo: string;
  idCard: string;
  currentAddress: string;
  infectiousDiseaseHistory: string;
  geneticDiseaseInfo: string;
  createPeople: string;
}) {
  return axioswnewmedical.post('/Patient/AddPatient', data);
}

// 修改患者信息接口
export function updatePatient(data: {
  id: number;
  accountId: number;
  name: string;
  sex: boolean;
  dateOfBirth: string;
  contactInfo: string;
  idCard: string;
  currentAddress: string;
  infectiousDiseaseHistory: string;
  geneticDiseaseInfo: string;
  updatePeople: string;
}) {
  return axioswnewmedical.put('/Patient/UpdatePatient', data);
}

// 新增医院接口
export function addHospital(data: {
  hospitalName: string;
  level: string;
  hospitalTypeId: number;
  contactInfo: string;
  region: string;
  image?: string;
  detailedAddress: string;
  departmentIds: number[];
  numberOfDoctors: number;
  numberOfDepartments: number;
  hospitalIntroduction: string;
  isRecommended: boolean;
  createPeople: string;
}) {
  return axioswnewmedical.post('/Hospital/AddHospital', data);
}

// 删除医院接口
export function deleteHospitals(data: {
  ids: number[];
  updatePeople: string;
}) {
  return axioswnewmedical.delete('/Hospital/DeleteHospitals', { data });
}

// 修改医院接口
export function updateHospital(data: {
  id: number;
  hospitalName: string;
  level: string;
  hospitalTypeId: number;
  contactInfo: string;
  region: string;
  image?: string;
  detailedAddress: string;
  departmentIds: number[];
  numberOfDoctors: number;
  numberOfDepartments: number;
  hospitalIntroduction: string;
  isRecommended: boolean;
  updatePeople: string;
}) {
  return axioswnewmedical.put('/Hospital/UpdateHospital', data);
}

// 新增一级科室接口
export function addFirstLevelDepartment(data: {
  departmentName: string;
  type: string;
  paretId: number;
  departmentAddr: string;
  isEmergencyService: boolean;
  isOnline: boolean;
  remark?: string;
  createPeople: string;
}) {
  return axioswnewmedical.post('/Department/AddFirstLevelDepartment', data);
}

// 新增二级科室接口
export function addSecondLevelDepartment(parentId: number, data: {
  departmentName: string;
  type: string;
  paretId: number;
  departmentAddr: string;
  isEmergencyService: boolean;
  isOnline: boolean;
  remark?: string;
  createPeople: string;
}) {
  return axioswnewmedical.post(`/Department/AddSecondLevelDepartment?parentId=${parentId}`, data);
}

// 新增科室接口（保持向后兼容，一级科室使用）
export function addDepartment(data: {
  departmentName: string;
  type: string;
  paretId: number;
  departmentAddr: string;
  isEmergencyService: boolean;
  isOnline: boolean;
  remark?: string;
  createPeople: string;
}) {
  return axioswnewmedical.post('/Department/AddFirstLevelDepartment', data);
}

// 修改科室接口（一二级通用）
export function updateDepartment(data: {
  id: number;
  departmentName: string;
  type: string;
  paretId: number;
  departmentAddr: string;
  isEmergencyService: boolean;
  isOnline: boolean;
  remark?: string;
  updatePeople: string;
}) {
  return axioswnewmedical.put('/Department/UpdateDepartment', data);
}

// 删除科室接口（一二级通用）
export function deleteDepartments(data: {
  ids: number[];
  updatePeople: string;
}) {
  return axioswnewmedical.delete('/Department/DeleteDepartments', { 
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 删除单个医生
export function deleteDoctor(id: number) {
  return axioswnewmedical.delete(`/Doctor/${id}`);
}

// 批量删除医生
export function batchDeleteDoctors(ids: number[]) {
  return axioswnewmedical.delete('/Doctor/batch', { data: ids });
}

export {axiosw,axioswmedical,axiosimg,axioswnewmedical}